#include "stdafx.h"

#include "FilterCombo.h"

namespace ui
{
	std::wstring FilterCombo::GetText()
	{
		//return GetSelItemData().v;
		return m_pRichEdit->GetText();
	}
	void FilterCombo::SetText(std::wstring sText)
	{
		assert(!"don't use FilterCombo::SetText, please use FilterCombo::SelectItem instend");
		m_bUpdatingData = true;
		m_pRichEdit->SetText(sText);
		m_bUpdatingData = false;
	}
	void FilterCombo::UpdateData(bool bHideListWnd)
	{
		m_sFilter = L"";
		std::wstring sText, sImage;
		assert(m_mapSel.size() < 2);
		for each (auto it in m_mapSel)
		{
			int nDataIndex = it.first;
			if (nDataIndex >= 0 && nDataIndex < m_vecItemData.size())
			{
				assert(sText.empty());
				sText = m_vecItemData[nDataIndex].v;
				if (IsImageMode())
				{
					std::string img = m_vecItemData[nDataIndex].img;
					if (!img.empty() && m_mapImage.find(img) != m_mapImage.end())
						sImage = m_mapImage.find(img)->second;
				}
				break;
			}
		}
		m_pImage->SetVisible(!sImage.empty());
		m_pImage->SetBkImage(sImage);
		
		m_bUpdatingData = true;
		m_pRichEdit->SetText(sText);
		m_bUpdatingData = false;
		printf("CFilterCombo::UpdateData\n");
		if (bHideListWnd)
			m_pListWnd->ShowListWnd(false);
	}

} // namespace ui
